﻿using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace HogoLogic
{
	[Serializable]
	public class HogoProjectList 
	{
		static private readonly BinaryFormatter formatter = new BinaryFormatter();

		private Collection<HogoProject> projects = new Collection<HogoProject>();

		public Collection<HogoProject> Projects
		{
			get { return projects; }
		}

		public void SaveToFile(string fileName)
		{
			Stream stream = File.Open(fileName, FileMode.Create);
			formatter.Serialize(stream, projects);
			stream.Close();
		}

		public void LoadFromFile(string fileName)
		{
			try
			{
				Stream stream = File.Open(fileName, FileMode.Open);
				projects = (Collection<HogoProject>) formatter.Deserialize(stream);
				stream.Close();
			}
			catch
			{
				projects = new Collection<HogoProject>();
			}
		}

	}
}
